
!(async function(){
   
var pieChart= echarts.init(document.getElementById('echmap'));
response=await taskObject.fetchtemplate(path='/getmap')
var totalSubjects = response.data[0]; 
var actualStudyCount = response.data[1];
var percentage = ((actualStudyCount / totalSubjects) * 100).toFixed(2) + '%';




 var option = {
    title: {
        text: '学生学习率可视化(选课率)'
    },
    tooltip: {
        trigger: 'item',
        formatter: function (params) {
            if (params.name === '已学习') {
                return '已学习科目: ' + actualStudyCount + ' (' + percentage + '%)';
            } else {
                return '未学习科目: ' + (totalSubjects - actualStudyCount) + ' (' + (100 - percentage).toFixed(2) + '%)';
            }
        }
    },
    series: [
        {
            name: 'Study Progress',
            type: 'pie',
            radius: '55%',
            center: ['50%', '50%'],
            data: [
                { name: '学习('+percentage+')', value: actualStudyCount },
                { name: '未学习', value: totalSubjects - actualStudyCount }
            ],
            emphasis: {
                itemStyle: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ]

};

// 使用配置和数据显示图表
pieChart.setOption(option);
}())


!(async function(){
    data=await taskObject.fetchtemplate(path='/api/user/getmessages')
  
    var myChart = echarts.init(document.getElementById('chart'));
    var positiveCount = 0;
    var neutralCount = 0;
    var negativeCount = 0;

    data.forEach(function(item) {
        if (item === 2) {
            positiveCount++;
        } else if (item === 1) {
            neutralCount++;
        } else if (item === 0) {
            negativeCount++;
        }
    });

    // 绘制图表
    var option = {
        title: {
            text: '学习态度情感分析图'
        },
        tooltip: {},
        xAxis: {
            data: ['积极', '中立', '消极']
        },
        yAxis: {},
        series: [{
            name: '态度分析',
            type: 'bar',
            data: [positiveCount, neutralCount, negativeCount],
            itemStyle: {
                // 为不同的数据类别设置不同的颜色
                color: function(params) {
                    var colorList = ['#2f4554', '#61a0a8', '#d48265'];
                    return colorList[params.dataIndex];
                }
            }
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
}())